package com.tcs.test.spring.process;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

public class ActionBeanPostProcessor implements BeanPostProcessor {

    private final Logger logger = LoggerFactory.getLogger(ActionBeanPostProcessor.class);

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        TestController testController = bean.getClass().getAnnotation(TestController.class);
        if (null != testController) {
            Method [] methods = bean.getClass().getMethods();
            for (Method met : methods) {
                ActionMap actionMap = met.getAnnotation(ActionMap.class);
                if(actionMap!=null){
                    logger.info(" bean : {} , beanName: {} ", bean.toString() , beanName);
                }
            }
        }
        return bean;
    }
}
